//
//  XWCell.m
//  CustomizeCell
//
//  Created by xiewei on 16/6/18.
//  Copyright © 2016年 xiewei. All rights reserved.
//

#import "XWCell.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

@interface XWCell()
/// 图片
@property (nonatomic,weak) UIImageView *imgView;

@end

@implementation XWCell

+ (instancetype)xwCellWithTableView:(UITableView *)tableView {
    NSString *reuseId = @"xwcell";
    XWCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId];
    }
    return cell;
}

#pragma mark - 重写父类的初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        /// 创建子控件
        UIImageView *imgView = [[UIImageView alloc] init];
        [self.contentView addSubview:imgView];
        self.imgView = imgView;
    }
    return self;
}

#pragma mark - 重写set方法
- (void)setUrlStr:(NSString *)urlStr {
    /// 1) 给本方法对应的成员变量赋值
    _urlStr = urlStr;
    
    /// 2) 给子控件赋值
    self.imgView.image = [UIImage imageNamed:_urlStr];
    
    /// 3）设置子控件的frame
    self.imgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100);
}
//- (void)layoutSubviews {
//    [super layoutSubviews];
//    
//    self.imgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100);
//}

@end
